package com.tpo;

import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import com.tpo.*;


public class tpoAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    	//asi declaras el activity, en el activity que lo queres iniciar, despues pones startActivity para iniciarlo
        //final Intent intent = new Intent(this, MapViewDemo.class);
        
        Button btn_start = (Button)findViewById(R.id.btn_start);
        btn_start.setOnClickListener(new OnClickListener(){
        	public void onClick(View v){
  	
        		//startActivity(intent);
        		//para iniciarlo
        		inamimate(); //para detener la animacion
        		
        		
        		Intent intent = new Intent(tpoAndroidActivity.this, formActivity.class);
        		startActivity(intent);
        		
        	}
        });
        
        
    }
    
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    	animate();
    	super.onWindowFocusChanged(hasFocus);
    }
    
    private void animate(){
    	ImageView imgView = (ImageView)findViewById(R.id.imagen);
    	imgView.setVisibility(ImageView.VISIBLE);
    	imgView.setBackgroundResource(R.drawable.frame_animation);
    	
    	AnimationDrawable frame = (AnimationDrawable) imgView.getBackground();
    	if(frame.isRunning()){
    		frame.stop();
    	}else{
    		frame.stop();
    		frame.start();
    	}
    }
    
    public void inamimate(){
    	ImageView imgView = (ImageView)findViewById(R.id.imagen);
    	imgView.setVisibility(ImageView.VISIBLE);
    	imgView.setBackgroundResource(R.drawable.frame_animation);
    	
    	AnimationDrawable frame = (AnimationDrawable) imgView.getBackground();
    	if(frame.isRunning()){
    		frame.stop();
    	}
    	
    }
    
    
}